package com.kaka.bus.engine.splash;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.bean.Version;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import java.util.Date;

import javax.inject.Inject;

/**
 * Created by zhangqi on 2016/10/8.
 * e-mail : ${email}
 * desc :
 */

public class SplashPresenter extends RxPresenter<SplashContract.View> implements SplashContract.Presenter{

    @Inject
    public SplashPresenter(DataManager dataManager) {
        super(dataManager);
    }


    @Override
    public void checkUpdate(String platform, String versionName) {
        addSubscribe(mDataManager
                .getApi()
                .getVersionInfo(Constant.VERSION,platform,versionName,new Date().getTime())
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<Version>>() {

                    @Override
                    protected void onSuccess(HttpWrapper<Version> data) {
                        mView.checkOk(data);
                    }

                    @Override
                    public void onError(Throwable t) {
                        super.onError(t);
                        mView.error();
                    }
                }));
    }
}
